use Test::Simple tests => 1;

use Zim::Formats::Wiki;
my $class = 'Zim::Formats::Wiki';

my $txt = wikipage();

my $tree = $class->load_tree($txt);
#use Data::Dumper; print STDERR Dumper $tree;
my $newtxt = $class->save_tree($tree);
#print STDERR "\n---->>\n", $newtxt, "<<----\n";

ok($txt eq $newtxt, 'formatter round trip');

sub wikipage {
return << 'EOT';
====== Foo Bar ======

This is a **test page** to see how parsing goes
when ''we'' ''loop'',
arbitrary //content// through our __parser__

    ($ROOT, $PAGE, @BACK, @FORW, $UNDO, $REDO);
    	my (%tree_iter, $tree_loaded, $pane_visible);
    	my (@undo_chars, $undo_lock, $save_lock, $overwrite_toggle);
    	my %undo_steps = (
           delete => 'insert', insert => 'delete',
           apply_tag => 'remove_tag', remove_tag => 'apply_tag' );
    	my $link_icon = Gtk2->CHECK_VERSION(2, 6, 0) ? 'gtk-connect' : 'gtk-convert';
           # gtk-connect stock item was introduced in 2.6.0
    	my $DATA_DIR  = find_data_dir();
    	my $ICON_FILE = File::Spec->catfile($DATA_DIR, qw/images zim64.png/);

    my %opts = ( 'read_only' => 0 );
    for (@ARGV) {
            next unless /^-/;
            if (/^(--version|-v)$/) {
                    print version();
                    exit;
            }
            elsif (/^--read-?o
                 my $iter = $buffer->get_iter_at_mark($buffer->get_insert());
                    return parse_backspace($iter);
            }
            elsif ($val == $k_tab or $val == ord(' ')) { # Other WhiteSpace
                    my $buffer = $self->get_buffer;
                    my $iter = $buffer->get_iter_at_mark($buffer->get_insert());
                    my $string = ($val == $k_tab) ? "\t" : ' ';
                    return parse_word($iter, $string);
            }
            #else { printf "key %x pressed\n", $val } # perldoc -m Gtk2::Gdk::Keysyms

    return 0; } )
    unless $opts{read_only};

    Glib::Timeout->add(5000, \&save_page)
            unless $opts{read_only}; # TODO also use this timer for maintaining an undo stack

    # ################# # 

===== So =====
what do we need to type
* to make
	* the parser
	* vomit
		* ???

==== Hmmm ====

dfsfds
sdfd
fdsfdsfdsfds





fsdfds

=== fdsfds ===

123 test

sdffdsfds
EOT
}
